
import os
import sys
from openai import OpenAI

# 添加项目根目录到Python路径，以便导入config_reader模块
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(os.path.dirname(current_dir))
sys.path.append(project_root)

from config_reader import get_bailian_config

# 从配置文件获取百炼配置
bailian_config = get_bailian_config()
bailian_api_token = bailian_config['token']

if not bailian_api_token:
    raise ValueError("请在 config.ini 文件中设置 BAILIAN_API_TOKEN")

client = OpenAI(
    # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx",
    api_key=bailian_api_token,
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen-vl-plus",
    # 此处以qwen-vl-plus为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
    messages=[{"role": "user", "content": [
        {"type": "image_url",
         "image_url": {"url": "https://het-sob.cos.clife.cn/file/20250903181438_be0c5958ac3e4511bc9d6b5c67590795.jpg"}},
        {"type": "text", "text": "这是什么"},
    ]}]
)
print(completion.model_dump_json())
